/**
 * @author gao
 * @date 2025/6/24 21:51
 */

public class Demo6 {
    public static void main(String[] args) throws InterruptedException {
        // 获取主线程
        Thread mainThread = Thread.currentThread();
        Thread t = new Thread(() -> {
            try {
                System.out.println("t线程等待之前");
                mainThread.join();
                System.out.println("t线程等待之后");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t.start();

        // 主线程等待t线程
        for (int i = 0; i < 10; i++) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
